<?php
!defined('IN_TOA') && exit('Access Denied!');

//刷新缓存
function recache($cachestr = '') {
	if (!$cachestr) {
		$cachelist = array('usergroup');
	} else {
		$cachelist = explode(',',$cachestr);
	}
	foreach ($cachelist as $cache) {
		$cachename = $cache.'_recache';
		if (function_exists($cachename)) {
			$cachename();
		}
	}
}

//将字符串写进文件
function write_to_file($cachename,$content = '') {
	if (is_array($content)) {
		$content = "\$_CACHE['$cachename'] = ".var_export($content,True).';';
	}
	$content = "<?php\n//该文件是系统自动生成的缓存文件，请勿修改\n//创建时间：".get_date('Y-m-d H:i:s',time())."\n\nif (!defined('IN_TOA')) {exit('Access Denied!');}\n\n".$content."\n\n?>";
	$filename = CACHE_ROOT.'cache_'.$cachename.'.php';
	$len = file_put_contents($filename, $content);
	@chmod($filename, 0777);
	return $len;
}

//缓存配置信息
/*function config_recache() {
	global $db;
	$content = array();
	$sql = "SELECT * FROM ".DB_TABLEPRE."config";
	$query = $db->query($sql);
	while ($row = $db->fetch_array($query)) {
		$content[$row['type']][$row['name']] = $row['value'];
	}
	//写入文件
	write_to_file('config',$content);
}*/


//缓存用户组
function usergroup_recache() {
	global $db;
	$sql = "SELECT * FROM ".DB_TABLEPRE."usergroup";
	$query = $db->query($sql);
	while ($row = $db->fetch_array($query)) {
		$content = "<?php\n//该文件是系统自动生成的缓存文件，请勿修改\n//创建时间：".get_date('Y-m-d H:i:s',time())."\n\nif (!defined('IN_TOA')) {exit('Access Denied!');}\n\n";
		$content .= "\$groupname = '$row[groupname]';\n";
		$content .= "\$purview = ".var_export(unserialize($row['purview']), true);
		$content .= "\n?>";
		$filename = CACHE_ROOT.'cache_usergroup_'.$row['id'].'.php';
		file_put_contents($filename, $content);
		@chmod($filename, 0777);
		
	}
	
}

?>